package com.ggg.gkd.controllerv1;

import com.ggg.gkd.servicev1.impl.TestServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("TestController")
public class TestController {

    @Resource
    public TestServiceImpl testService;
    @GetMapping("/get")
    public String showGet(int id){

        testService.setUserId(id);
        return Integer.toString(testService.getId());
    }

    @PostMapping("/post")
    public String showPost(String name, String sex, int age){
        testService.setUserAttribute(name, sex, age);
        return name + "," + sex + "性," + age + "周岁";
    }

    @PutMapping("/put")
    public String showPut(String name, String sex, int age){
        testService.setUserAttribute(name, sex, age);
        String mark;
        if(age >= 18)
        {
            mark = "已成年";
        }
        else
        {
            mark = "未成年";
        }
        return "{name:”" + name + "”,sex:”" + sex  + "“,age:”" + age + "”，mark: “" + mark + "”}";
    }

    @DeleteMapping("/delete")
    public String showDelete(String name, String sex, int age){
        if (testService.getName().equals(name) && testService.getSex().equals(sex) && testService.getAge() == age)
        {
            return "张三信息已删除";
        }
        else
        {
            return "未找到该条信息";
        }
    }
}
